package com.yb.bussiness.goods;

import java.util.List;

import com.yb.base.dao.BaseDao;
import com.yb.base.dao.IBaseDao;
import com.yb.domain.goods.TgCategoryMessage;

public class CategoryMessageServiceImpl implements CategoryMessageService {
	private IBaseDao<TgCategoryMessage, Long> dao;

	public CategoryMessageServiceImpl() {
		dao = new BaseDao<TgCategoryMessage, Long>(TgCategoryMessage.class);
	}

	public TgCategoryMessage findByParams(Long pcategoryId, Long categoryId,
			Integer type, Integer type2) {
		String sql = "select * from t_g_category_message where pcategoryId = ? and categoryId = ? and type = ? and type2 = ?";
		List<TgCategoryMessage> list = dao.findList(sql, new Object[] {
				pcategoryId, categoryId, type, type2 });
		if (null != list && list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

	public void saveOrUpdate(TgCategoryMessage obj) {
		dao.saveOrUpdate(obj);
	}

	public String getAnnouncement(Long categoryId) {
		String sql = "select * from t_g_category_message where pcategoryId = (select pid from t_g_category where id = ?) and categoryId = -1 and type = 1 and type2 = 1";
		List<TgCategoryMessage> list = dao.findList(sql,
				new Object[] { categoryId });
		if (null != list && list.size() > 0) {
			return list.get(0).getContent();
		}
		return null;
	}

	public String getStateMent(Long categoryId) {
		String sql = "select * from t_g_category_message where categoryId = ? and type = 1 and type2 = 2";
		List<TgCategoryMessage> list = dao.findList(sql,
				new Object[] { categoryId });
		if (null != list && list.size() > 0) {
			return list.get(0).getContent();
		}
		return null;
	}

	public String getAnnouncement4Good(Long categoryId) {
		String sql = "select * from t_g_category_message where pcategoryId = (select pid from t_g_category where id = ?) and categoryId = -1 and type = 2 and type2 = 1";
		List<TgCategoryMessage> list = dao.findList(sql,
				new Object[] { categoryId });
		if (null != list && list.size() > 0) {
			return list.get(0).getContent();
		}
		return null;
	}

	public String getStateMent4Good(Long categoryId) {
		String sql = "select * from t_g_category_message where categoryId = ? and type = 2 and type2 = 2";
		List<TgCategoryMessage> list = dao.findList(sql,
				new Object[] { categoryId });
		if (null != list && list.size() > 0) {
			return list.get(0).getContent();
		}
		return null;
	}

}
